package com.tungse.study.io.two;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class Client2 {

    public static void main(String[] args) throws IOException {
        //1 创建 socket对象 请求服务端的链接
        Socket socket = new Socket("127.0.0.1", 9999);
        //2 从socket对象中获取输入流和输出流
        OutputStream os = socket.getOutputStream();
        //3 把字节输出流包装成一个打印流
        PrintStream ps = new PrintStream(os);
        Scanner sc = new Scanner(System.in);
        while (true)  {
            System.out.print("请输入要发送的内容：");
            String msg = sc.nextLine();
            //把数据发送给服务端
            ps.println(msg);
            ps.flush();//刷新缓冲区
        }


    }
}
